<template>
    <div>
        <div class="mainBox">
            <ul>
                <li :class="index==subjectindex?'hover':''" v-for="(item,index) in modellist" @click="qhsubject(item.itemCaseFlagId,index,item.nav6id)" :key="index">{{item.nav6name}}</li>
            </ul>
        </div>
        <div class="mainBox">
            <ul>
                <li :class="tabnumber==1?'hover':''" @click="studentorder(1)">客观题设置</li>
                <li :class="tabnumber==2?'hover':''" @click="studentorder(2)">主观题设置</li>
            </ul>
            <div>
                满分：{{parseInt(objectiveTotalscore+subjectiveTotalscore)}} =  {{objectiveTotalscore}}（{{objectivequestionslist.length}}道客观题）+  {{subjectiveTotalscore}}（{{subjectivequestionslist.length}}道主观题）
                <el-button type="primary" size="small" @click="copysubjectlcik" v-if="tabnumber==1">复用模板</el-button>
            </div>
        </div>
        <!-- 客观题设置 -->
        <objectiveQuestion :modellist="modellist" v-if="tabnumber==1" :type="1" @updateobjectivequestionssurebc="updateobjectivequestionssurebc" :questiontid="questiontid" :objectivequestionslist="objectivequestionslist" @emitobjectivequestion="emitobjectivequestion"></objectiveQuestion>
        <!-- 主观题设置 -->
        <subectiveQuestion v-if="tabnumber==2" :type="2" :subjectivequestionslist="subjectivequestionslist" @emitsubjectivequestion="emitsubjectivequestion"></subectiveQuestion>
        <!-- 创建复用考试 -->
		<examCopy v-if="examCopyIshow" @copyexamclick="copyexamclick" :type="2" :examnavid="examnavid" :subjectid="questiontid" :subjectidname="subjectidname"></examCopy>
    </div>
</template>

<script>
import examCopy from '../../../components/model/copysubject.vue'
import objectiveQuestion from '../../../components/model/objectivequestion.vue'
import subectiveQuestion from '../../../components/model/subectivequestion.vue'
import {modelItemcaselist,getSubjectiveQuestions,getObjectiveQuestions} from '../../../api/api.js'
export default {
    name: 'projectoverview',
    data () {
        return {
            // stopexamlist:[
            //     {
            //         name:'[12345]语文',
            //         subject:'语文',
            //         status:'上传开始',
            //         modelname:'250414语文内蒙3卷',
            //         schoolname:'北京小学',
            //         ipadress:'192.168.1.1',
            //     }
            // ],
            multipleSelection:[],
            examCopyIshow:false,
            pageSize:50, 
            currentPage:1,
            total:0,
            tabnumber:1,
            options:[],
            subjectlist:[{id:1,name:'语文'},{id:2,name:'数学'},{id:3,name:'英语'},{id:4,name:'物理'},{id:5,name:'化学'},{id:6,name:'生物'},{id:7,name:'历史'},{id:8,name:'地理'},],
            subjectindex:0,
            modellist: [{}], // 表格数据
            subjectid:'',
            subjectivequestionslist:[], // 主观题
            objectivequestionslist:[], // 客观题
            questiontid:'', // 客观题id
            objectiveTotalscore:0,
            subjectiveTotalscore:0,
        }
    },
    computed: {
        examId() {
            return this.$store.state.examId;
        }
    },
    watch: {
    	examId(newVal) {
            if (newVal) {
                this.examnavid = newVal;
                // this.overviewlist(newVal);
                this.getsubjectlistclick(newVal)
                this.$store.commit('setExamId', ''); // 重置状态
            }
        }	
    },
    mounted() {
        this.examcontent = JSON.parse(sessionStorage.getItem('examContent'))
         this.examnavid = this.examcontent.nav5id
        this.getsubjectlistclick(this.examcontent.nav5id)
    },
    methods: {
        updateobjectivequestionssurebc(){
            this.getsubjectlistclick(this.examcontent.nav5id)
        },
        onSelected(){
				
			},
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        copyexamclick(data){
            this.examCopyIshow = false
            if(data==1){
                this.getsubjectlistclick(this.examnavid)
            }
            
        },
        copysubjectlcik(){
            this.examCopyIshow = true
        },
        studentorder(number){
            this.tabnumber = number   
        },
        // 获取学科
        getsubjectlistclick(id){
            let obj = {
                nav5id:id
            }
            modelItemcaselist(obj).then(res=>{
                if(res.code==0){
                    if(res.obj.length==0){
                        this.modellist = []
                        this.$message({
                            message: '暂无数据',
                            type: 'error'
                        });
                        return
                    }
                    this.modellist = res.obj
                    this.questiontid = res.obj[0].itemCaseFlagId
                    this.subjectivequestionclick(res.obj[0].itemCaseFlagId)
                    this.objectivequestionclick(res.obj[0].itemCaseFlagId)
                    this.subjectidname = res.obj[0].nav6id
                }else{
                    this.$message({
                        message: res.msg,
                        type: 'error'
                    });
                }
            })
        },
        //获取主观题
        subjectivequestionclick(id){
            let obj={
                itemCaseflagid:id
            }
            getSubjectiveQuestions(obj).then(res=>{
                console.info('res',res)
                if(res.code==0){
                    this.subjectivequestionslist = res.obj
                    const totalScore = res.obj.reduce((sum, item) => {
                        return sum + (parseFloat(item.highestscore) || 0)
                    }, 0)
                    this.subjectiveTotalscore = totalScore
                }else{
                    this.$message({
                        message: res.msg,
                        type: 'error'
                    }); 
                }
            })
        },
        qhsubject(id,num,nav6id){
            this.subjectindex = num
            this.questiontid = id
            this.subjectidname = nav6id
            this.subjectivequestionclick(id)
            this.objectivequestionclick(id)
        },
        //获取客观题
        objectivequestionclick(id){
            let obj={
                itemCaseflagid:id
            }
            getObjectiveQuestions(obj).then(res=>{
                if(res.code==0){
                    this.objectivequestionslist = res.obj
                    const totalScore = res.obj.reduce((sum, item) => {
                        return sum + (parseFloat(item.highestscore) || 0)
                    }, 0)
                    this.objectiveTotalscore = totalScore
                }else{
                    this.$message({
                        message: res.msg,
                        type: 'error'
                    }); 
                }
            })
        },
        // 批量删除客观题
        emitobjectivequestion(data){
            this.objectivequestionclick(this.questiontid)
        },
        emitsubjectivequestion(data){
            this.subjectivequestionclick(this.questiontid)
        }
    },
    components: {
        examCopy,objectiveQuestion,subectiveQuestion
    }
}
</script>

<style scoped>
.mainBox{
    background:#fff;
    margin-bottom:15px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding:15px;
}
.mainBox >>> .el-button{
    background:#366EF4;
    border:solid 1px #366EF4;
    height:36px;
}
.mainBox >>> .el-select .el-input__inner{
	 width:150px; 
     margin-left:4px;
     border-radius: 10px;
     height:36px;
}
.mainBox >>> .el-input__icon{
    line-height:36px;
}
.mainBox >>> .distpicker-address-wrapper select{
    height:35px;
    line-height:35px;
    border-radius:10px;
    font-size:14px;
    color:#999;
    border:solid 1px #DCDFE6;
}
.mainBox ul{
    display: flex;
    align-items: center;
}
.mainBox ul li{
    font-size:14px;
    margin-right:15px;
    padding:0 10px;
    line-height:36px;
    cursor: pointer;
    border-bottom:solid 2px #fff;
}
.mainBox ul li:hover,.mainBox ul li.hover{
    color:#0052D9;
    border-bottom:solid 2px #0052D9;
}

    .scopednr b{
        display: inline-block;
        font-weight:normal;
        margin:0 8px;
        color:#165DFF;
        cursor: pointer;
    }
    .scopednr b:last-child{
        color:#D54941
    }
    
</style>